
 


<html>
 <head>
 <title>AnnotationReference</title>
 </head>
 <body>




 <div id="wikicontent">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
 
 <td class="vt" id="wikimaincol" width="100%">
 
 <div id="wikiheader" style="margin-bottom:1em">
 
 <span style="font-size:120%;font-weight:bold">AnnotationReference</span>
 &nbsp;
 
 
 <div style="font-style:italic; margin-top: 3px">The annotations used by Objectify</div>
 
 </div>
 <h1><a name="Example"/>Example</h1><pre class="prettyprint">@Cached(expirationSeconds=600)
@Entity(name=&quot;Emp&quot;)
@Indexed // or @Unindexed sets default for fields in class; if neither specified, assume @Indexed
class Employee {
   @Id long id;
   @Parent Key&lt;Company&gt; employer;

   @Unindexed int vacationDays;

   // field getting renamed
   @AlsoLoad(&quot;boss&quot;) Key&lt;Employee&gt; manager;

   String firstName;
   String lastName;

   // we used to store fullName, now we store first and last separately
   public void oldWay(@AlsoLoad(&quot;fullName&quot;) String fullName)
   {
       String[] split = fullName.split(&quot; &quot;);
       firstName = split[0];
       lastName = split[1];
   }

   static class Office {
      String building;
      String room;
   }

   // Allows you to query for employess in a building by filtering on &quot;offices.building&quot;
   @Embedded Office[] offices;

   // Whatever gets put here will be serialized out and back (and cannot be filtered)
   @Seralized Object misc;

   @PostLoad void onLoad() { /* do something after load */ }
   @PrePersist void onPersist() { /* do something before persisting */ }
}</pre><h1><a name="The_Annotations"/>The Annotations</h1><h2><a name="@javax.persistence.Entity"/>@javax.persistence.Entity</h2><ul><li>Optional, can be placed on a class. </li><li>Optionally specifies the name of a kind, ie <tt>@Entity(name=&quot;Person&quot;)</tt> </li></ul><h2><a name="@com.googlecode.objectify.annotation.Entity"/>@com.googlecode.objectify.annotation.Entity</h2><ul><li>An alternate annotation that behaves the same as javax.persistence.Entity. </li><li>Won&#x27;t be recognized by any classpath scanning tools that look for the other annotation. </li></ul><h2><a name="@javax.persistence.Id"/>@javax.persistence.Id</h2><ul><li>Must be placed on one and only one field of an @Entity class </li><li>Field must be type <tt>Long</tt>, <tt>long</tt>, or <tt>String</tt> </li><li>If used on type <tt>Long</tt>, null values will be autogenerated on put() </li></ul><h2><a name="@com.googlecode.objectify.annotation.Indexed"/>@com.googlecode.objectify.annotation.Indexed</h2><ul><li>Placed on a field or class. </li><li>When placed on a class, sets the default state for all fields of the class. </li><li>Can take <tt>If</tt> conditions which allow partial indexing. </li><li>@Indexed state is inherited by embedded classes and their fields, but can be overriden with @Unindexed. </li><li>Indexed fields cost more space and cpu time to store, but can be queried on. </li><li>Translates to <tt>Entity.setProperty()</tt> at the low-level api. </li><li>Unless otherwise specified, all classes default to @Indexed. </li></ul><h2><a name="@com.googlecode.objectify.annotation.Unindexed"/>@com.googlecode.objectify.annotation.Unindexed</h2><ul><li>Placed on a field or class. </li><li>When placed on a class, sets the default state for all fields of the class. </li><li>Can take <tt>If</tt> conditions which allow partial indexing. </li><li>@Unindexed state is inherited by embedded classes and their fields, but can be overridden with @Indexed. </li><li>Unindexed fields consume less space and require less cpu time to store, but cannot be queried for. </li><li>Translates to <tt>Entity.setUnindexedProperty()</tt> at the low-level api. </li></ul><h2><a name="@com.googlecode.objectify.annotation."/>@com.googlecode.objectify.annotation.NotSaved</h2><ul><li>Placed on a field. </li><li>Can take <tt>If</tt> conditions which specify particular values which are not saved. </li><li>Field is still loaded as normal. </li></ul><h2><a name="@com.googlecode.objectify.annotation."/>@com.googlecode.objectify.annotation.AlsoLoad</h2><ul><li>Placed on a field or the single parameter to a method </li><li>Requires one value, the name of a property in the datastore to load into the field. </li><li>Example:  <tt>@AlsoLoad(&quot;whatThisFieldUsedToBeCalled&quot;)</tt> </li><li>Causes the field to be loaded from an alternate name in the underlying datastore </li><li>If placed on the parameter to a method that takes a single parameter, the method will be called with the datastore value </li><li>If there is a load conflict with the true name of field, an IllegalStateException will be thrown. </li></ul><h2><a name="@com.googlecode.objectify.annotation.Parent"/>@com.googlecode.objectify.annotation.Parent</h2><ul><li>Placed on at most one field of type <tt>Key</tt> </li><li>Defines the entity group parent for an entity </li></ul><h2><a name="@com.googlecode.objectify.annotation.Cached"/>@com.googlecode.objectify.annotation.Cached</h2><ul><li>Placed on an entity class </li><li>Stores entity data in a write-through cache for faster read performance </li><li>Allows you to specify the expiration of entities in the cache </li></ul><h2><a name="@javax.persistence.Embedded"/>@javax.persistence.Embedded</h2><ul><li>Placed on an entity field, or the field of any class embedded in an entity. </li><li>Field can be any custom type or a collection or array of your custom type. </li><li>See the <a href="http://code.google.comIntroductionToObjectify.html#@Embedded" rel="nofollow">@Embedded</a> documentation. </li></ul><h2><a name="@com.googlecode.objectify.annotation.Serialized"/>@com.googlecode.objectify.annotation.Serialized</h2><ul><li>Placed on any entity field of Serializable type </li><li>Causes the object graph at that point to be stored as a serialized Blob. </li><li>Can be used on fields inside @Embedded classes. </li><li>See the <a href="http://code.google.comIntroductionToObjectify.html#@Serialized" rel="nofollow">@Serialized</a> documentation. </li></ul><h2><a name="@javax.persistence."/>@javax.persistence.PostLoad</h2><ul><li>Placed on any method that either takes no parameters or a single parameter of type Entity. </li><li>Called after the POJO is populated with data. </li><li>Can be specified on multiple methods in this class or any base class. </li><li>Methods are called in declared order, with superclass methods first. </li></ul><h2><a name="@javax.persistence."/>@javax.persistence.PrePersist</h2><ul><li>Placed on any method that either takes no parameters or a single parameter of type Entity. </li><li>Called before the POJO is written to the datastore Entity. </li><li>Can be specified on multiple methods in this class or any base class. </li><li>Methods are called in declared order, with superclass methods first. </li></ul>
 </td> 
 </tr>
 </table>
 </div>



 <script src="http://www.gstatic.com/codesite/ph/17891623693695439908/js/dwiki_scripts_20081003.js"></script>



 </body>
</html>

